package com.bdqn.service.common;

import com.bdqn.mapper.common.AppVersionMapper;
import com.bdqn.pojo.AppVersion;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AppVersionServiceImpl implements AppVersionService {
    @Resource
    private AppVersionMapper appVersionMapper;

    @Override
    public AppVersion getVersionById(Long id) {
        AppVersion appVersion = appVersionMapper.getVersionById(id);
        if (appVersion != null) {
            return appVersion;
        }
        return null;
    }

    @Override
    public List<AppVersion> getAppVersionList(Long appId) {
        List<AppVersion> appVersions = appVersionMapper.getAppVersionList(appId);
        if (appVersions!=null){
            return appVersions;
        }
        return null;
    }

    @Override
    public boolean addVersion(AppVersion appVersion) {
        if (appVersionMapper.addVersion(appVersion) == 1){
            return true;
        }
        return false;
    }

    @Override
    public Long getMaxId() {
        Long id = Long.valueOf(appVersionMapper.getMaxId());
        return id;
    }

    @Override
    public boolean delFile(Long id) {
        if (appVersionMapper.delFile(id)==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateVersion(AppVersion appVersion) {
        if (appVersionMapper.updateVersion(appVersion) == 1){
            return true;
        }
        return false;
    }

    @Transactional
    @Override
    public int checkByAppIdCount(Long appId) {
        return appVersionMapper.checkByAppIdCount(appId);
    }

    @Transactional
    @Override
    public boolean delByAppId(Long appId) {
        if (appVersionMapper.delByAppId(appId)>0){
            return true;
        }
        return false;
    }
}
